package com.yangjie.web.example;
import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

@Controller   
public class RosterController {
    private List<Member> members = new ArrayList<Member>();
    
    
    @Inject private RosterService rosterService;
    
    
    public RosterService getRosterService() {
		return rosterService;
	}


	public void setRosterService(RosterService rosterService) {
		this.rosterService = rosterService;
	}


	public RosterController() {
        members.add(new Member("John", "Lennon"));
        members.add(new Member("Paul", "McCartney"));
        members.add(new Member("George", "Harrison"));
        members.add(new Member("Ringo", "Starr"));
    }
    
    
    @RequestMapping(value="/roster/list", method = RequestMethod.GET)       
    
    public void list(Model model) {          
    	System.out.println("request1.............");
        model.addAttribute("memberList", members);
        rosterService.print();
    }
    
    
    @RequestMapping(value="/roster/*", method = RequestMethod.POST)
    public void member(@RequestParam("id") Integer id, Model model) {   
        model.addAttribute(members.get(id));
    }
}
